#include <iostream>
#include "exception.hpp"
#include "contactservice.hpp"
#include "httplib.h"
void menu()
{
    std::cout << "-----------------------------------------------------" << std::endl
              << "--------------- 请选择对通讯录的操作 ----------------" << std::endl
              << "------------------ 1、新增联系人 --------------------" << std::endl
              << "------------------ 2、删除联系人 --------------------" << std::endl
              << "------------------ 3、查看联系人列表 ----------------" << std::endl
              << "------------------ 4、查看联系人详细信息 ------------" << std::endl
              << "------------------ 0、退出 --------------------------" << std::endl
              << "-----------------------------------------------------" << std::endl;
}

enum OPERATE
{
    _ADD = 1,
    _DEL,
    _FIND_ALL,
    _FIND_ONE
};

int main()
{

    while (1)
    {
        menu();
        std::cout << "---> 请选择：";
        int choose;
        std::cin >> choose;
        std::cin.ignore(256, '\n');
        ContactsServer contactsServer; // 进行相关业务请求发送
        try
        {

            switch (choose)
            {
            case OPERATE::_ADD:
                contactsServer.addContact();
                break;
            case OPERATE::_DEL:
                contactsServer.delContact();
                break;
            case OPERATE::_FIND_ALL:
                contactsServer.findContacts();
                break;
            case OPERATE::_FIND_ONE:
                contactsServer.findContact();
                break;
            case 0:
                std::cout << "---> 程序已退出" << std::endl;
                return 0;
            default:
                std::cout << "---> 无此选项，请重新选择！" << std::endl;
                break;
            }
        }

        catch (const Exception &e)
        {

            std::cerr << "---> 操作通讯录时发现异常！！！" << std::endl
                      << "---> 异常信息：" << e.what() << std::endl;
        }
    }

    return 0;
}